# Make a chart of oil income per capita in
# Iran and Saudi Arabia

##################################################
# Section 1: R Housekeeping
##################################################

#  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  # 
# Section 1.1: Clear R workspace
#  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #

rm(list=ls(all=TRUE))

#  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  # 
# Section 1.2: Set Working Directory 
#  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #


# Change this to  your working directory
mywd <- "/Users/paulmusgrave/Dropbox/0001 Academic Projects/Ongoing/0127 Oil Islam Women/ISQ Accepted Submission/Replication"

setwd(paste(mywd,"/Data",sep=""))


#  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  # 
# Section 1.3: Load Data
#  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #
library(foreign)
library(arm)
library(lmtest)
library(sandwich)

longData <- read.dta("ISQFINALRossTSData.dta")

setwd(paste(mywd,"/Drafts/Charts",sep=""))

pdf("ISQFINALAppendixFigure03.pdf",height=8, width=8)
plot(longData[longData$cty_name=="Saudi Arabia",]$year,
longData[longData$cty_name=="Saudi Arabia",]$oil_gas_valuePOP_2009,
		type="l",
		lty=1,
		col="darkgreen",
		main="Saudi and Iranian Oil Income Per Capita, 1960-2012",
		ylab="Oil Income in 2009 USD",
		xlab="",
		lwd=2)
lines(longData[longData$cty_name=="Iran, Islamic Rep.",]$year,
		longData[longData$cty_name=="Iran, Islamic Rep.",]$oil_gas_valuePOP_2009,
		lty=2,
		lwd=2)
legend("topright", inset=.05, legend=c("Iran","Saudi Arabia"),col=c("black","darkgreen"),lty=c(2,1),lwd=2)
dev.off()

# Plot index chart (1973 = 100)
saudi.index <- longData[longData$cty_name=="Saudi Arabia",]$oil_gas_valuePOP_2009/longData[longData$cty_name=="Saudi Arabia" & longData$year == 1974,]$oil_gas_valuePOP_2009
saudi.index <- saudi.index*100

iran.index <- longData[longData$cty_name=="Iran, Islamic Rep.",]$oil_gas_valuePOP_2009/longData[longData$cty_name=="Iran, Islamic Rep." & longData$year == 1974,]$oil_gas_valuePOP_2009
iran.index <- iran.index*100

pdf("ISQFINALAppendixFigure04.pdf",height=8, width=8)

plot(c(1960:2011),
	saudi.index,
		type="l",
		lty=1,
		col="darkgreen",
		main="Saudi and Iranian Oil Income Per Capita, 1960-2012",
		ylab="Oil Income in 1973 = 100",
		xlab="",
		lwd=2)
lines(c(1960:2011),
	iran.index,
		lty=2,
		lwd=2)
abline(h=100,lty=2,col="black")
legend("topright", inset=.05, legend=c("Iran","Saudi Arabia"),col=c("black","darkgreen"),lty=c(2,1),lwd=2)
dev.off()

